home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / appletalk / netatalk / afs / afskrbsrc.sit.hqx / AFS Kerberos 1.0B0 / uam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-14  |  6.2 KB  |  274 lines

  1. /*
  2.  * Copyright (c) 1990 Regents of The University of Michigan.
  3.  * All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appears in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation, and that the name of
  10.  * The University of Michigan not be used in advertising or
  11.  * publicity pertaining to distribution of the software without
  12.  * specific, written prior permission. This software is supplied as
  13.  * is without expressed or implied warranties of any kind.
  14.  *
  15.  *    ITD Research Systems
  16.  *    University of Michigan
  17.  *    535 W. William Street
  18.  *    Ann Arbor, Michigan
  19.  *    +1-313-936-2652
  20.  *    netatalk@terminator.cc.umich.edu
  21.  */
  22.  
  23. #include <Memory.h>
  24. #include <files.h>
  25. #include <dialogs.h>
  26. #include <appletalk.h>
  27. #include <packages.h>
  28. #include <resources.h>
  29. #include <script.h>
  30. #include <errors.h>
  31. #include <ctype.h>
  32. #include <string.h>
  33. #include <quickdraw.h>
  34. #include <toolutils.h>
  35. #include <cursorctl.h>
  36.  
  37. /*
  38.  * MIT Kerberos and DES stuff
  39.  */
  40. #include <des.h>
  41. #include <krb.h>
  42. #include <conf.h>
  43. #include <prot.h>
  44.  
  45. #include "uam.h"
  46.  
  47. /*
  48.  * function prototypes
  49.  */
  50. OSErr    uam_open( Str255 name, Str255 zone );
  51. OSErr    uam_close( void );
  52. OSErr    uam_pwd_dialog( StringHandle name, char *passwd );
  53. OSErr    uam_login( AddrBlock addr, short xrefnum, short retry, Ptr attn, Str255 name, char *passwd,
  54.             short *srefnum, Ptr *scb );
  55.  
  56. extern char     afp_server[];
  57. extern char     afp_zone[];
  58. Handle        afp_iconhdl;
  59. Boolean        afp_dosetpw;
  60. DialogPtr    passwd_dlp;
  61. acurHandle    acur_hdl;
  62.  
  63. pascal OSErr
  64. uam_dispatch( opcode, new_A5p, addr, xrefnum, retry, attn, name, passwd, srefnum, scb )
  65.     long        opcode;
  66.     long        *new_A5p;
  67.     AddrBlock    addr;
  68.     short        xrefnum, retry, *srefnum;
  69.     Ptr        attn, *scb;
  70.     Str255        name;
  71.     char        *passwd;
  72. /*
  73.  * "opcode" is 1 for uam_open, 2 for uam_close, 3 for uam_pwd_dialog, 4 for uam_login
  74.  * "new_A5p" is set if opcode is "uam_open"
  75.  * the remainder of the above paramaters are correct for uam_login
  76.  * for uam_open, "attn" above is actually "name" and "name" above is actually "zone"
  77.  * for uam_pwd_dialog, "name" and "passwd" are as above
  78.  * for uam_close, none of the parameters are used
  79.  */
  80. {
  81.     Ptr    globalmem;
  82.     long    old_A5;
  83.     OSErr    rc;
  84.     
  85.     if ( opcode == OP_UAM_OPEN ) {
  86. /*        DebugStr( "\puam initial open" );    /* */
  87.         /*
  88.          * initialize area off A5 for globals
  89.          */
  90.         if (( globalmem = NewPtr( A5Size())) == NULL ) {
  91.             return( -1 );
  92.         }
  93.         mysetup_A5( globalmem, new_A5p ); 
  94.     }
  95.     
  96.     old_A5 = SetA5( *new_A5p );
  97.     
  98.     switch( opcode ) {
  99.         case OP_UAM_OPEN:
  100.             /* DebugStr( "\puam_open" );    /* */
  101.             mysetup_QD( old_A5 );
  102.             rc = uam_open( (Str255)attn, (Str255)name );
  103.             break;
  104.         case OP_UAM_CLOSE:
  105.             /* DebugStr( "\puam_close" );    /* */
  106.             rc = uam_close();
  107.             break;
  108.         case OP_UAM_PWDDLOG:
  109.             /* DebugStr( "\puam_pwdialog" );    /* */
  110.             name[ 0 ] = 0;
  111.             rc = uam_pwd_dialog( (char **)name, passwd );
  112.             break;
  113.         case OP_UAM_LOGIN:
  114.             /* DebugStr( "\puam_login" );    /* */
  115.             rc = uam_login( addr, xrefnum, retry, attn, name, passwd,
  116.                     srefnum, scb );
  117.             break;
  118.         default:
  119.             rc = -1;
  120.     }
  121.     SetA5( old_A5 );
  122.     
  123.     if ( opcode == OP_UAM_CLOSE ) {
  124.         /* DebugStr( "\puam final close" );    /* */
  125.         globalmem = (Ptr) (*new_A5p - A5Size() + 32);
  126.         DisposPtr( globalmem );
  127.     }
  128.     
  129.     return( rc );
  130. }
  131.  
  132.  
  133. OSErr
  134. uam_open( name, zone )
  135.     Str255    name, zone;
  136. {
  137.     AddrBlock    addr;
  138.     Handle        iconhdl;
  139.     short        iorefnum;
  140.     
  141.     /*
  142.      * save name and zone of server in global space
  143.      * (for mutual verification of authentication)
  144.      */
  145.     BlockMove( name, afp_server, *name + 1 );
  146.     afp_server[ name[ 0 ] + 1 ] = '\0';
  147.     BlockMove( zone, afp_zone, *zone + 1 );
  148.     afp_zone[ zone[ 0 ] + 1 ] = '\0';
  149.     
  150.     /*
  151.      * get icon from server via ASP status call
  152.      */
  153.     if ( OpenXPP( &iorefnum ) != noErr ) {
  154.         doalert( ALRT_LOCALERR );
  155.         return( -1 );
  156.     }
  157.     
  158.     if ( lookup_address( afp_server, NBPTYPE_AFP, afp_zone , &addr ) != 0 ) {
  159.         doalert( ALRT_REMOTEERR );
  160.         return( -1 );
  161.     }
  162.     if ( get_server_status( iorefnum, addr, &afp_iconhdl, &afp_dosetpw ) != 0 ) {
  163.         return( -1 );
  164.     }
  165.     
  166.     /*
  167.      * load acur (spinning watch cursor) resource
  168.      */
  169.     if (( acur_hdl = (acurHandle)Get1Resource( 'acur', ACUR_WATCH )) == NULL ) {
  170.         doalert( ALRT_LOCALERR );
  171.         return( -1 );
  172.     }
  173.     HLock( (Handle)acur_hdl );
  174.     InitCursorCtl( acur_hdl );
  175.     
  176.     return( noErr );
  177. }
  178.  
  179.  
  180. OSErr
  181. uam_close( newA5 )
  182. {
  183.     if ( afp_iconhdl != NULL ) {
  184.         DisposHandle( afp_iconhdl );
  185.     }
  186.     
  187.     HUnlock( (Handle)acur_hdl );
  188.     ReleaseResource( (Handle)acur_hdl );
  189.     return( noErr );
  190. }
  191.  
  192. OSErr
  193. uam_pwd_dialog( name, passwd )
  194.     char        *name;        /* P-string */
  195.     char        *passwd;    /* C-string */
  196. {
  197.     InitCursor();
  198.     ParamText( NULL, afp_server, NULL, NULL );
  199.     passwd_dlp = passwddialog( name, passwd, afp_iconhdl, UAM_PASSWD_DLOG,
  200.             true, 0, afp_dosetpw );
  201.     
  202.     if ( passwd_dlp == NULL ) {
  203.         bzero( passwd, MAXPASSWDLEN );
  204.         return( -1 );
  205.     } 
  206.     return( 0 );
  207. }
  208.  
  209.  
  210. OSErr
  211. uam_login( addr, xrefnum, retry, attn, name, passwd, srefnum, scb )
  212.     AddrBlock    addr;
  213.     short        xrefnum, retry, *srefnum;
  214.     Ptr        attn, *scb;
  215.     char        *name;            /* P-string */
  216.     char        *passwd;
  217. {
  218.     AFPLoginPrm        alp;
  219.     unsigned char        logoutcmd = afpLogout;
  220.     Handle            hdl;
  221.     short            oresfile;
  222.     des_cblock        sesskey;
  223.  
  224.     oresfile = CurResFile();
  225.     if (( hdl = GetResource( 'uamn', 0 )) == NULL ) {
  226.         return( -1 );
  227.     }
  228.     UseResFile( HomeResFile( hdl ));
  229.         
  230.     for (;;) {
  231.         bzero( &alp, sizeof( AFPLoginPrm ));
  232.         alp.ioRefNum = xrefnum;
  233.         alp.aspTimeout = retry;
  234.         alp.afpAddrBlock = addr;
  235.         alp.afpAttnRoutine = attn;
  236.         *scb = alp.afpSCBPtr = NewPtrSysClear( scbMemSize );
  237.         
  238.         if ( dologin( true, true, &alp, name, passwd, srefnum, sesskey ) == 0 ) {
  239.             break;    /* success! */
  240.         }
  241.         
  242.         /*
  243.          * An error occurred during the login process.
  244.          * Send a Logout command to the server.
  245.          */
  246.         alp.cbPtr = &logoutcmd;
  247.         alp.cbSize = 1;
  248.         alp.rbSize = 0;
  249.         alp.rbPtr = NULL;
  250.         alp.ioCompletion = NULL;
  251.         if ( AFPCommand( (XPPParmBlkPtr)&alp, true ) == noErr ) {
  252.             wait_for_completion( (XPPParmBlkPtr)&alp );
  253.         }
  254.         DisposPtr( *scb );
  255.         
  256.         /*
  257.          * perform password dialog again (in case user just made a typo)
  258.          */
  259.         DisposDialog( passwd_dlp );
  260.         if ( uam_pwd_dialog( name, passwd ) != 0 ) {
  261.             UseResFile( oresfile );
  262.             ReleaseResource( hdl );
  263.             return( -1 );
  264.         }
  265.     }
  266.     
  267.     /*
  268.      * successful login....
  269.      */
  270.     DisposDialog( passwd_dlp );
  271.     UseResFile( oresfile );
  272.     ReleaseResource( hdl );
  273.     return( noErr );
  274. }